//
//  SQMainCell.m
//  pai
//
//  Created by pro on 14-11-6.
//  Copyright (c) 2014年 linjunjing. All rights reserved.
//

#import "SQMainCell.h"
#import "UIImageView+WebCache.h"
#import "Global.h"

@implementation SQMainCell

- (IBAction)doActionMore:(id)sender {
    if (self.delegate) {
        [self.delegate clickMore:self.titleLabel.text];
    }
}

+(SQMainCell*)initmyview
{
    NSArray* nibView =  [[NSBundle mainBundle] loadNibNamed:@"SQMainCell" owner:nil options:nil];
    return [nibView objectAtIndex:0];
}
-(void)onClickImageLeft:(UIImageView*)imageview
{
    NSMutableDictionary* dic = [self.myarr objectAtIndex:0];
    if (self.delegate) {
        [self.delegate clickImagewithType:self.titleLabel.text Dictionary:dic];
    }
}
-(void)onClickImageRight:(UIImageView*)imageview
{
    NSMutableDictionary* dic = [self.myarr objectAtIndex:1];
    if (self.delegate) {
        [self.delegate clickImagewithType:self.titleLabel.text Dictionary:dic];
    }
}
-(id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if(self)
    {
        
    }
    return self;
}
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}
-(void)setInfo:(NSMutableArray*)arr
{
    self.myarr = [[NSMutableArray alloc]initWithArray:arr];
    //self.myarr = arr;
    NSLog(@"%lu",(unsigned long)self.myarr.count);
    if (arr.count == 0) {
        //首页无内容
        [self.leftImageView setHidden:YES];
        [self.leftLabel setHidden:YES];
        
        [self.rightImageView setHidden:YES];
        [self.rightLabel setHidden:YES];
    }else if (arr.count == 1){
        //显示一个
        [self.rightImageView setHidden:YES];
        [self.rightLabel setHidden:YES];
        
        NSDictionary* dic = [arr objectAtIndex:0];
        NSString* url = [NSString stringWithFormat:@"%@%@",IMAGESERVICE,[dic objectForKey:@"home_photo"]];
        [self.leftImageView setImageWithURL:[NSURL URLWithString:url]];
        [self.leftLabel setText:[NSString stringWithFormat:@"%@",[dic objectForKey:@"home_intro"]]];
    }else{
        //显示
        NSDictionary* dic = [arr objectAtIndex:0];
        NSString* url = [NSString stringWithFormat:@"%@%@",IMAGESERVICE,[dic objectForKey:@"home_photo"]];
        [self.leftImageView setImageWithURL:[NSURL URLWithString:url]];
        [self.leftLabel setText:[NSString stringWithFormat:@"%@",[dic objectForKey:@"home_intro"]]];
        
        dic = [arr objectAtIndex:1];
        url = [NSString stringWithFormat:@"%@%@",IMAGESERVICE,[dic objectForKey:@"home_photo"]];
        [self.rightImageView setImageWithURL:[NSURL URLWithString:url]];
        [self.rightLabel setText:[NSString stringWithFormat:@"%@",[dic objectForKey:@"home_intro"]]];
    }
    
    UITapGestureRecognizer *singleTapLeft =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onClickImageLeft:)];
    self.leftImageView.userInteractionEnabled=YES;
    self.leftImageView.tag = 1000;
    [self.leftImageView addGestureRecognizer:singleTapLeft];
    UITapGestureRecognizer *singleTapRight =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onClickImageRight:)];
    self.rightImageView.userInteractionEnabled=YES;
    self.rightImageView.tag = 1001;
    [self.rightImageView addGestureRecognizer:singleTapRight];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
